﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: Propietario			*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System.Collections.Generic;
using System.ServiceModel;

using ESF.SSO.Core.Entities;
using ESF.SSO.Core.BusinessLogic;
using ESF.WCF;
using ESF.SSO.Core.Entities.Log;
using ESF.General.Entity;
using System.Linq;
using ESF.SSO.Core.Entities.BasicReferences;

#endregion


namespace ESF.SSO.Service.Client
{
	[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
	[ExceptionBehaviorAttribute]
	public class SSOService : ISSOService
	{
		#region Read
		
		public User SignInByCredentials (User pUser)
		{
			return CtrlUser.SignInByCredentials (pUser);
		}
		
		
		public User SignInByIdentificationCredentials (User pUser)
		{
			return CtrlUser.SignInByIdentificationCredentials (pUser);
		}


		public List<UserMenuItem> GetUserMenu(User pUser, BasicReference pApplication)
		{
			return CtrlUser.GetUserMenu (pUser, pApplication).ToList ();
		}
		
		
		public void CloseSession (UserSessionLog pUserSessionLog)
		{
			CtrlUser.CloseSession (pUserSessionLog);
		}
		
		
		public void CloseSessionByCredentials (User pUser)
		{
			CtrlUser.CloseSessionByCredentials (pUser);
		}
		
		
		public void CloseSessionByIdentificationCredentials (User pUser)
		{
			CtrlUser.CloseSessionByIdentificationCredentials (pUser);
		}
		
		
		public void SignUp (User pUser)
		{
			CtrlUser.SignUp (pUser);
		}
		
		
		public User GetUserFromSessionID (string pSessionID)
		{
			return CtrlUser.GetUserFromSessionID (pSessionID);
		}


		public BasicReference GetUserRightValue (User pUser, string pRightCode)
		{
			return CtrlUser.GetUserBasicReferenceValue (pUser, 
				new BasicReference () { Code = pRightCode, 
					BasicReferenceType = new BasicReferenceType () { ID = (int) BasicReferenceTypes.UserRights } });
		}

		
		public void SetUserRightValue (User pUser, BasicReference pRight)
		{
			CtrlUser.SetUserRightValue (pUser, pRight);
		}

		#endregion
		
		
		#region Rights

		public List<BasicReference> GetUserRights(User pUser)
		{
			return CtrlUser.GetUserBasicReferenceValues (pUser, BasicReferenceTypes.UserRights).ToList ();
		}
		
		#endregion
		
		
		#region Lists
		
		public List<BasicReference> ListBasicReference (BasicReferenceType pBasicReferenceType)
		{
			return CtrlBasicReference.List (pBasicReferenceType).ToList ();
		}
		
		
		public List<UserMenuItem> GetUserApplicationList (User pUser)
		{
			return CtrlUser.GetUserApplicationList (pUser).ToList ();
		}
		
		#endregion
		
		
		#region BasicReference
		
		public BasicReference GetBasicReferenceByCode (string pBasicReferenceCode)
		{
			return CtrlBasicReference.Get (new LocatedBasicReference () { Code = pBasicReferenceCode });
		}
		
		
		public BasicReference GetBasicReferenceByID (int pBasicReferenceID)
		{
			return CtrlBasicReference.Get (new LocatedBasicReference () { ID = pBasicReferenceID });
		}
		
		#endregion
		
		
		#region Images
		
		//public List<FileReference> GetUserMenuImages (User pUser, BasicReference pApplication)
		//{
		//    return CtrlUser.GetUserMenuImages (pUser, pApplication).ToList ();
		//}
		
		#endregion
	}
}
